﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using IndustrialSmokeCalc.SmokeCalcWCF;

namespace IndustrialSmokeCalc
{
    public partial class AddChimney : PhoneApplicationPage
    {
        public AddChimney()
        {
            InitializeComponent();
        }

        private void btnAddChimney_Click(object sender, RoutedEventArgs e)
        {
            double latitude = DataSingleton.Instance.Chimney.GeoCoordinate.Latitude;
            double longitude = DataSingleton.Instance.Chimney.GeoCoordinate.Longitude;

            SmokeCalcClient client = new SmokeCalcClient();
            client.AddChimneyCompleted += AddChimneyCompleted;
            client.AddChimneyAsync(DataSingleton.Instance.CompanyId, txtChimneyName.Text, txtChimneyDescription.Text, latitude, longitude);
        }

        private void AddChimneyCompleted(object sender, AddChimneyCompletedEventArgs e)
        {
            if (e.Result == "sukses")
            {
                GetChimneyId();
            }
            else
            {
                MessageBox.Show(e.Result);
            }
        }

        private void GetChimneyId()
        {
            SmokeCalcClient client = new SmokeCalcClient();
            client.GetChimneyIdCompleted += GetChimneyIdCompleted;
            //client.GetChimneyIdAsync(DataSingleton.Instance.CompanyId, txtChimneyName.Text);
        }

        private void GetChimneyIdCompleted(object sender, GetChimneyIdCompletedEventArgs e)
        {
            DataSingleton.Instance.ChimneyId = e.Result;
            NavigationService.Navigate(new Uri("/Form.xaml", UriKind.Relative));
        }
    }
}